import 'package:bruno/bruno.dart';
import 'package:common/common.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../../app_config/api_constants.dart';
import '../../../global_web/global_web_page.dart';

/// @description:
/// @author
/// @date: 2024-09-20 13:47:43
class AboutMePage extends StatelessWidget {
  const AboutMePage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: BrnAppBar(title: '关于我们', backgroundColor: Colors.white),
        backgroundColor: Colors.white,
        body: Column(
          children: [
            Expanded(
                child: Column(
              children: [
                Container(
                    padding: const EdgeInsets.all(20),
                    margin: EdgeInsets.only(top: 100.h),
                    child: Image.asset('assets/app/images/auth/auth_logo.png', width: 100, height: 100)),
                Text('喵趣',
                    style: TextStyle(color: const Color(0xFF000000), fontSize: 16.sp, fontWeight: FontWeight.w600)),
              ],
            )),
            Expanded(
                child: Column(
              children: [
                _buildItem(
                    title: '用户协议',
                    isShowLine: true,
                    action: () {
                      GlobalWebPage.startInstance("用户协议", ApiConstants.userAgreementUrl);
                    }),
                _buildItem(
                    title: '隐私政策',
                    action: () {
                      GlobalWebPage.startInstance("隐私政策", ApiConstants.privacyPolicyUrl);
                    }),
              ],
            )),
            Container(
                padding: EdgeInsets.only(left: 15.w, right: 15.w, bottom: 30),
                child: GestureDetector(
                  onTap: () async {
                    Toast.showLoading();
                    Uri uri = Uri.parse(ApiConstants.miitGovLink);
                    bool canLaunch = await canLaunchUrl(uri);
                    if (canLaunch) {
                      await launchUrl(uri);
                      Toast.dismiss();
                    } else {
                      Toast.showLoading();
                      GlobalWebPage.startInstance('备案信息', ApiConstants.miitGovLink);
                    }
                  },
                  child: Container(
                    height: 61.h,
                    padding: EdgeInsets.symmetric(horizontal: 15.w),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        RichText(
                            textAlign: TextAlign.center,
                            maxLines: 3,
                            overflow: TextOverflow.ellipsis,
                            strutStyle: const StrutStyle(leading: 0, forceStrutHeight: true, height: 1.5),
                            text: const TextSpan(
                              children: [
                                TextSpan(
                                    text: '北京马开科技有限公司 \n', style: TextStyle(color: Color(0xff999999), fontSize: 11)),
                                TextSpan(
                                  text: ApiConstants.miitGovCode,
                                  style: TextStyle(
                                      color: Color(0xFF25D4D0), fontSize: 11, decoration: TextDecoration.underline),
                                ),
                              ],
                            ))
                      ],
                    ),
                  ),
                ))
          ],
        ));
  }

  Widget _buildItem({required String title, Function? action, bool isShowLine = false}) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        action?.call();
      },
      child: Container(
        color: title.isNotEmpty ? Colors.white : Colors.transparent,
        padding: EdgeInsets.symmetric(horizontal: 15.w),
        child: title.isNotEmpty
            ? Column(
                children: [
                  Container(
                    padding: const EdgeInsets.symmetric(vertical: 15),
                    child: Row(
                      children: [
                        Text(title + '  ',
                            style: TextStyle(fontSize: 15.sp, color: Colors.black, fontWeight: FontWeight.w500)),
                        const Spacer(),
                        const Icon(Icons.navigate_next_sharp, size: 25, color: Color(0xFF000000)),
                      ],
                    ),
                  ),
                  if (isShowLine) const Divider(color: Color(0xFFEEEEEE), height: 0.5)
                ],
              )
            : const SizedBox(height: 10),
      ),
    );
  }
}
